package cn.com.dragonsoftbravo.utils.azure.factory;

import cn.com.dragonsoftbravo.utils.SystemConfigHolder;

import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.services.servicebus.ServiceBusConfiguration;
import com.microsoft.windowsazure.services.servicebus.ServiceBusContract;
import com.microsoft.windowsazure.services.servicebus.ServiceBusService;

public class ServiceBusContractFactory {

	private static ServiceBusContract service;

	private static String sbNamespace;

	private static String sbSasKeyName;

	private static String sbSasKey;

	private static String sbServiceBusRootUri;

	static {
		sbNamespace = SystemConfigHolder.instance().getValue("sbNamespace");
		sbSasKeyName = SystemConfigHolder.instance().getValue("sbSasKeyName");
		sbSasKey = SystemConfigHolder.instance().getValue("sbSasKey");
		sbServiceBusRootUri = SystemConfigHolder.instance().getValue("sbServiceBusRootUri");
	}

	public static void init() {
		BlobClientFactory.initConnection();
		Configuration config = ServiceBusConfiguration.configureWithSASAuthentication(sbNamespace,
				sbSasKeyName, sbSasKey, sbServiceBusRootUri);
		
		service = ServiceBusService.create(config);
	}

	public static ServiceBusContract getSerivceBusContract() {
		if (null == service) {
			init();
		}
		return service;
	}

}
